<template>
  <div>
    <el-input placeholder="请输入内容" clearable style="width: 370px" v-model="selectContent"> </el-input
    ><el-button type="primary" style="width: 80px" @click="getNewFriend()">搜索</el-button>
    <el-table :data="tableData" height="500" style="width: 100%">
      <el-table-column label="是否为您的好友" width="180">
        <template slot-scope="scope">
          <i class="el-icon-time"></i>
          <span style="margin-left: 10px">{{ scope.row.having?'是':'否'}}</span>
        </template>
      </el-table-column>
      <el-table-column label="姓名" width="180">
        <template slot-scope="scope">
          <el-popover trigger="hover" placement="top">
            <p>姓名: {{ scope.row.username }}</p>
            <p>ID: {{ scope.row.userid }}</p>
            <div slot="reference" class="name-wrapper">
              <el-tag size="medium">{{ scope.row.username }}</el-tag>
            </div>
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
            size="mini"
            style="width: 120px"
            @click="handleEdit(scope.$index, scope.row)"
            v-if="!scope.row.having"
            >发送好友申请</el-button
          >
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>


<script>
export default {
  data() {
    return {
      selectContent:'',
      tableData: [],
      sendInput:false
    };
  },
  methods: {
    handleEdit(index, row) {
      console.log(index, row);
      this.$http.post(`/system/tbApply/sendApply`,{userid:JSON.parse(localStorage.getItem("userInfo")).userid,friendid:row.userid})
      .then(res=>{
        if(res.data.code==200){
          this.$notify({
          title: '成功',
          message: '发送成功',
          type: 'success'
        });
        }
      })
    },
    getNewFriend(){
      this.$http
      .get(`/system/sysUser/getUserLikeUserName?userid=${JSON.parse(localStorage.getItem("userInfo")).userid}&friendname=${this.selectContent}`)
      .then(res=>{
        console.log(res.data.data)
        this.tableData=res.data.data
      })
    }
  },
};
</script>